package org.btik.light.mobile.platform.util;


import java.io.ByteArrayOutputStream;


public class ByteBuffer extends ByteArrayOutputStream {

    public ByteBuffer(int count) {
        super(count);
    }

    public ByteBuffer() {
    }

    /**
     * 返回无符号byte -1则是不存在
     */
    public int at(int index) {
        if (index < -1 || index >= count) {
            return -1;
        }
        return buf[index];
    }

    public int last() {
        if (count > 0) {
            return buf[count - 1];
        }
        return -1;
    }

    /**
     * 会重置
     */
    public synchronized DefaultRawReport takeMsg() {
        DefaultRawReport defaultRawReport = new DefaultRawReport(toByteArray());
        this.reset();
        return defaultRawReport;
    }

}
